{include file='common/head' /}
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <div class="layui-form" type="post">
                    <input type="hidden" name="type" value="finance">
                    <fieldset class="layui-elem-field layui-field-title">
                        <legend>购物券设置</legend>
                    </fieldset>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            购物券名称:
                        </label>
                        <div class="layui-col-md4" style="text-align: left">
                            <input style="width:100%" type="text" name="name" required="" autocomplete="off" class="layui-input" value="{$data.name|default=0}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            初始额度:
                        </label>
                        <div class="layui-col-md4" style="text-align: left">
                            <input style="width:100%" type="number" name="initial" required="" autocomplete="off" class="layui-input" value="{$data.initial|default=0}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            购买价格:
                        </label>
                        <div class="layui-col-md4" style="text-align: left">
                            <input style="width:100%" type="number" name="price" required="" autocomplete="off" class="layui-input" value="{$data.price|default=0}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            加入团队业绩:
                        </label>
                        <div class="layui-col-md4" style="text-align: left">
                            <input type="radio" name="is_team" value="1" title="是" {if condition="$data['is_team'] eq 1"}checked{/if}>
                            <input type="radio" name="is_team" value="0" title="否" {if condition="$data['is_team'] eq 0"}checked{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            开启分销设置:
                        </label>
                        <div class="layui-col-md4 goods_role" style="text-align: left">
                            <input type="radio" name="is_sale" value="1" title="是" {if condition="$data['is_sale'] eq 1"}checked{/if}>
                            <input type="radio" name="is_sale" value="0" title="否" {if condition="$data['is_sale'] eq 0"}checked{/if}>
                        </div>
                    </div>
                    <div class="role" {if condition="$data['is_sale'] eq 0"}style="display:none;"{/if}>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            分佣方式:
                        </label>
                        <div class="layui-col-md4 type" style="text-align: left">
                            <input type="radio" name="sale_type" value="1" title="百分比" {if condition="$data['sale_type'] eq 1 or empty($data['sale_type'])"}checked{/if}>
                            <input type="radio" name="sale_type" value="2" title="固定值" {if condition="$data['sale_type'] eq 2"}checked{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            比例:
                        </label>
                        <div class="layui-col-md4" style="text-align: left">
                            <input style="width:90%;padding-left: 10px;height: 30px;line-height: 30px;" type="number" name="sale_val" required="" autocomplete="off" lay-verify="required" value="{$data.sale_val|default=0}">
                            <span class="code">
                                {if condition="!empty($data['sale_type'])"}
                                {if condition="$data['sale_type'] eq 1"}%{else /}元{/if}
                                {else /}%{/if}
                            </span>
                        </div>
                    </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <button class="layui-btn" lay-filter="add" lay-submit="">确定保存</button></div>
                    </div>
                </form>
            </div>
        </div>
        <script>
            layui.use(['form', 'layer','jquery'],function() {
                $ = layui.jquery;
                var form = layui.form,layer = layui.layer;

                $('.goods_role').click(function () {
                    var val = $('input[name="is_sale"]:checked').val();
                    if(val == 1){
                        $('.role').css('display','');
                    }else{
                        $('.role').css('display','none');
                    }
                })

                $('.type').click(function () {
                    var val = $('input[name="sale_type"]:checked').val();
                    if(val == 1){
                        $('.code').html('%');
                    }else{
                        $('.code').html('元');
                    }
                })

                //监听提交
                form.on('submit(add)', function(data) {
                    $.ajax({
                        url:"{:url('Volumes/volumeEdit')}",
                        type: "post",
                        data:data.field,
                        dataType:"json",
                        success:function (res) {
                            if(res.code == 200){
                                layer.alert(res.msg, {icon: 1},function () {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                            }else{
                                layer.alert(res.msg, {icon:2,time:1000});
                            }
                        },
                        error:function(e){
                            layer.alert("网络错误", {icon:5,time:1000});
                        },
                    });
                    return false;
                });
            });
        </script>
{include file='common/footer' /}